<?php
	class loginpage
	{
		public $page;
		private $succses;
		
		public function __construct()
		{
			$_SESSION['user'] = new User($_POST['name'], $_POST['password']);
			if(!$_SESSION['user']->auth())
			{
				$this->succses = false;
				$this->page['title'] = "Login";
				$this->page['content'] = "<div id='loginPage'>
						<form method='post' name='login' action='?page=login'>
							<p>".$_SESSION['translation'][$_SESSION['lang']]["username"]." <input type='text' name='name' /></p>
							<p>".$_SESSION['translation'][$_SESSION['lang']]["password"]." <input type='password' name='password' /></p>
							<p><a href='javascript:document.login.submit();' class='button'>".$_SESSION['translation'][$_SESSION['lang']]["login"]." </a> <a href='?page=register' class='button'>".$_SESSION['translation'][$_SESSION['lang']]["register"]."</a></p>
						</form>
					</div>";
				}
				else
				{
					$this->succses = true;
					$this->page['title'] = "admin";
					$this->page['content'] = "<div>".$_SESSION['translation'][$_SESSION['lang']]["loginSucces"]." ".$_SESSION['user']->_name." </div>";
				}
		}
		
		public function getPage()
		{
			if(!$this->succses)
			{
				$page = $this->page;
				require_once("templates/ContentOnly.php");
			}
			else
			{
				$page = $this->page;
				require_once("templates/Main.php");
			}
		}
	}
?>